<template>
  <div style="margin:4px">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="用户账号" prop="userName">
        <el-input
          style="width: 140px"
          v-model.trim="queryParams.userName"
          placeholder="请输入用户账号"
          clearable/>
      </el-form-item>
      <el-form-item label="查询项目" prop="productId">
        <el-select
          style="width: 140px"
          v-model="queryParams.productId"
          placeholder="请选择"
          clearable>
          <el-option
            v-for="item in productOptions"
            :label="item.text"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="查询姓名" prop="name">
        <el-input
          style="width: 140px"
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable/>
      </el-form-item>
      <el-form-item label="身份证" prop="cardNo">
        <el-input
          style="width: 180px"
          v-model="queryParams.cardNo"
          placeholder="请输入身份证"
          clearable/>
      </el-form-item>
      <el-form-item label="电话号码" prop="tel">
        <el-input
          style="width: 140px"
          v-model="queryParams.tel"
          placeholder="请输入电话号码"
          clearable/>
      </el-form-item>

      <el-form-item label="设备标识" prop="sign">
        <el-input
          style="width: 140px"
          v-model="queryParams.sign"
          placeholder="请输入设备标识"
          clearable/>
      </el-form-item>
      <el-form-item label="关键字" prop="moreKeyword">
        <el-input
          style="width: 140px"
          v-model="queryParams.moreKeyword"
          placeholder="请输入关键字"
          clearable/>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:query:remove']">删除
        </el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="queryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="ID" align="center" prop="id"/>
      <el-table-column label="用户账号" align="center" prop="userName"/>
      <el-table-column label="查询项目" align="center" prop="productName"/>
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="身份证" align="center" prop="cardNo"/>
      <el-table-column label="电话" align="center" prop="tel"/>
<!--      <el-table-column label="关键字" align="center" prop="moreKeyword"/>-->
      <el-table-column label="查询结果" align="center" prop="queryInfo" :show-overflow-tooltip="true"/>
      <el-table-column label="设备标识" align="center" prop="sign"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:query:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"/>
  </div>
</template>

<script>
  import {listQuery, delQuery} from "@/api/system/query";
  import {distinctName} from "@/api/system/product";

  export default {
    name: "Query",
    data() {
      return {
        productOptions: [],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 查询进件表格数据
        queryList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,

          userName: null,
          productId: null,
          name: null,
          cardNo: null,
          tel: null,
          sign: null,
          moreKeyword: null
        }
      };
    },
    created() {
      this.getList();
      distinctName().then(res => {
        this.productOptions = res.product
      })
    },
    methods: {
      /** 查询查询进件列表 */
      getList() {
        this.loading = true;
        listQuery(this.queryParams).then(response => {
          this.queryList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除查询进件编号为"' + ids + '"的数据项？').then(function () {
          return delQuery(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      }
    }
  };
</script>
